/**
 * All rights Reserved, Designed By OprCalf
 * Copyright:    Copyright(C) 2016-2020
 * Company       LengYin Ltd.
 */

package com.platform.gateway.common.config;

import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;

/**
 * @projectName:  platform-gateway-demo
 * @package:      com.platform.gateway.common.configuration
 * @className:    HystrixConfiguration.java
 * @description:  断路器信息控制面板数据
 * @author:       OprCalf
 * @date:         2020年3月5日
 */
@Configuration
public class HystrixConfig {

    /**
     * 普通断路器信息
     * @author OprCalf
     * @return ServletRegistrationBean<HystrixMetricsStreamServlet>
     */
    @Bean(name = "hystrixRegistrationBean")
    public ServletRegistrationBean<HystrixMetricsStreamServlet> servletRegistrationBean() {
        final ServletRegistrationBean<HystrixMetricsStreamServlet> registration = new ServletRegistrationBean<>(
                new HystrixMetricsStreamServlet(), "/hystrix.stream");
        registration.setName("hystrixServlet");
        registration.setLoadOnStartup(1);
        return registration;
    }

    /**
     * 给turbine使用的断路器信息,跟上面一样的
     * @author OprCalf
     * @return ServletRegistrationBean<HystrixMetricsStreamServlet>
     */
    @Bean(name = "hystrixForTurbineRegistrationBean")
    public ServletRegistrationBean<HystrixMetricsStreamServlet> servletTurbineRegistrationBean() {
        final ServletRegistrationBean<HystrixMetricsStreamServlet> registration = new ServletRegistrationBean<>(
                new HystrixMetricsStreamServlet(), "/actuator/hystrix.stream");
        registration.setName("hystrixForTurbineServlet");
        registration.setLoadOnStartup(1);
        return registration;
    }

}
